package com.atguigu.day09;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.SqlDialect;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.catalog.hive.HiveCatalog;

public class Flink05_HiveCataLog {
    public static void main(String[] args) {
        //1.获取流&表执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);

        //TODO 2.创建HiveCatalog
        String name = "hiveCatalog";
        String defaultDatabase = "default";
        String confDir = "c:/conf";
        HiveCatalog hiveCatalog = new HiveCatalog(name, defaultDatabase, confDir);

        //TODO 3.在表执行环境中注册Catalog
        tableEnv.registerCatalog(name, hiveCatalog);

        //TODO 4.指定使用的数据库以及Catalog
        tableEnv.useCatalog(name);
        tableEnv.useDatabase(defaultDatabase);

        //TODO 指定Hive方言
        tableEnv.getConfig().setSqlDialect(SqlDialect.HIVE);

        //TODO 5.查询Hive中的数据
        tableEnv.executeSql("select * from plant_carbon").print();
    }
}
